 
  

 






<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=193 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:06 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
<head>
 <title>
  Java Practices -> Struts seems mediocre
 </title>
 <link rel="stylesheet" type="text/css" href="../stylesheet8.css" media="all">
 
 <link rel="shortcut icon" href='../images/favicon.ico' type="image/vnd.microsoft.icon">
 <meta name="description" content="Concise presentations of java programming practices, tasks, and conventions, amply illustrated with syntax highlighted code examples.">
 
 <meta name='keywords' content='Action,ActionForm,Struts,java,java programming,java practices,java idiom,java style,java design patterns,java coding conventions,'>
 
 
</head>
 
<body>


<div class='menu-bar'>
 
  <a href='../home/HomeAction.html' title='Table of Contents'>Home</a> |
  <a href='../vote/VoteSummaryAction-2.html' title='View Poll Results'>Poll</a> |
   
  <A href='../feedback/FeedbackAction451f-2.html?Operation=Show' title='Send Your Feedback'>Wiki</a> |
  <b><a href='../source/SourceAction-2.html' title='Grab Source Code'>Source Code</a></b><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |

  <a href='http://www.web4j.com/Java_Web_Application_Framework_Overview.jsp?From=1' title='Free Download - Java Web Application Framework'><b>WEB4J</b></a> |
  
  <a href='http://www.date4j.net/' title='Replacement for java.util.Date'><b>DATE4J</b></a> |

   <a href='../references/ReferencesAction-2.html' title='References'>Links</a>
   
  <form action='http://www.javapractices.com/search/SearchAction.do' method='get' class='search-form'>
   <input type='text' name='SearchTerms' value="" size=12 maxlength=50 class='search'>
   <input type='submit' value="Search">
  </form>
 
</div>

<P>



  

 






<p class="display-messages">

 

 

</p>


<div class="main-layout">
 
   

 




<div class='page-title'>Struts seems mediocre</div>

<div class='main-body'>
 
<br>The <a href="http://struts.apache.org/1.3.8/index.html">Struts 1</a> front end framework
was one of the first java web application tools to be published, and it
enjoys wide popularity.
<p>(Calling Struts an "application framework" is inaccurate. Struts assists
the developer in building only the front end of an application. It does
nothing for the model layer or the database layer. It is not a full stack framework.)

<p>It can be argued with some force that Struts 1 is a mediocre tool. Here
are some reasons why.
<p><b>No policies for translating request parameters into common java objects.</b>
<p>All java web applications need to translate raw request parameter values
into common items such as <tt>Integer</tt>, <tt>Date</tt>, and <tt>BigDecimal</tt>.
However, <i>Struts 1 provides no support for this task</i>. It
does not define reasonable default policies, nor does it encourage the
user to define such policies in any way.

<p><b>ActionForms are a massive parallel structure to the "real" model.</b>
<p>The <tt>ActionForm</tt> classes are not intended as the actual model.
They are intended as a preliminary validation buffer between the raw HTTP
request and the "real" model class. (For example, an <tt>ActionForm</tt>
might validate that a request parameter can be parsed into an <tt>Integer</tt>,
whereas the related model class might validate that the <tt>Integer</tt>
is within the range <tt>1..10</tt>.) <tt>ActionForm</tt>s include only
<tt>String</tt>
and <tt>boolean</tt> items, and nothing else. Since <tt>ActionForm</tt>s
and model classes exist as a pair, this creates <i>massive unnecessary
parallelism</i>.
<p>This point is closely related to the first one. If centrally defined
policies for translating request parameters into <tt>Integer</tt>, <tt>Date</tt>,
<tt>BigDecimal</tt>,
and so on, existed, then model objects could indeed be constructed out
of request parameters more or less directly.
<p>Furthermore, even though Struts 1 requires that model objects be constructed
out of related <tt>ActionForm</tt>s, it gives no direct support to the
programmer for performing this task.

<p><b>Data validation is separated from the Model Object.</b>
<P>A fundamental idea in object programming is to unite data with related actions.
Typical business applications are excellent for illustrating this 
idea, since business data usually has many related <em>validations</em>. 
Thus, the Model Object should typically encapsulate both data and validations.
In Struts 1, however, data validation is completely <em>separated</em> from the Model Object. 
Why? Why have the creators of Struts 1 lost sight of such a fundamental, basic idea in 
object programming? <em>It does not seem to have any justification.</em>

<p><b>Standard HTML forms are not used.</b>
<p>In Struts 1, forms usually depart widely from standard HTML, and are usually
implemented with a specific set of custom tags. This is neither necessary
nor desirable. It is not necessary since other tools have demonstrated
that dynamically populated forms can simply reuse standard HTML forms as
part of their implementation. It is not desirable since the page author
cannot reuse their knowledge of standard HTML, but is instead forced to
learn a new set of custom tags specific to Struts 1. This is unproductive.
<p><b>Actions must be thread-safe.</b>
<p><tt>Action</tt>s are always cached and reused by Struts 1. This is both
a performance optimization and a constraint, since it requires <tt>Action</tt>s
to be safe for use in a multi-threaded environment.
<p>As a performance optimization, this policy is of dubious quality. The
stack traces of a web container are large. If an <tt>Action</tt> is "just
another object", it is of very little benefit to cache and reuse it. On
the other hand, designs in which an <tt>Action</tt> holds a reference to
an expensive object (such as a database connection) are often inferior.
<p>As a constraint, Joshua Bloch explains clearly in <i><a href="http://www.amazon.com/exec/obidos/ASIN/0201310058/ref=nosim/javapractices-20">Effective
Java</a></i> that ensuring a class is usable in a multi-threaded environment
is a non-trivial task. Forcing all <tt>Action</tt> implementations to be
thread-safe seems an onerous requirement having doubtful benefit. For example,
in a Struts 1 <tt>Action</tt>, data shared between methods cannot be stored
in a field ; rather, it must be passed as a parameter.
<p><b>Struts 1 is an unimpressive implementation of the Command pattern.</b>
<p>The <tt>execute</tt> method has four arguments, which must always be
passed in, regardless of whether or not the argument is actually relevant
to a particular action. In the <i>Design Patterns</i> book, the number
of arguments to the <tt>execute</tt> method is exactly zero. There is a
good reason for this, and it is illustrated by almost every design pattern
in the Gang Of Four book : the central methods of any design are free of
implementation details. Data needed by the implementation of an abstraction
is almost always passed to a <i>constructor</i>. This keeps the abstractions
clean, and places data specific to the implementation in a place where
inheritance and polymorphism do not apply (the constructor).

<p>In addition, Struts 1 always requires a cast to be performed in an <tt>Action</tt>, 
to get access to a specific <tt>ActionForm</tt>.
Casts are something to be avoided unless absolutely necessary, since they
lead to runtime errors.
<p>The <a href="TopicAction5f31-2.html">web4j</a> tool was built out of strong dissatisfaction
with the Struts 1 front end framework.
<br>
<br>

</div>




<div class='topic-section'>See Also :</div>
<div class='main-body'>
 
  
  <a href='TopicAction703a-2.html?Id=138'>Parse parameters into domain objects</a> <br>
 
  
  <a href='TopicActionae2d-2.html?Id=139'>Command objects</a> <br>
 
  
  <a href='TopicAction9b6b-2.html?Id=177'>Pre-populate forms</a> <br>
 
  
  <a href='TopicAction5f31-2.html?Id=188'>A Web App Framework - WEB4J</a> <br>
 
</div>


<div class='topic-section'>Would you use this technique?</div>
<div class='main-body'>
  
  <form action="http://www.javapractices.com/vote/AddVoteAction.do" method='post'>
    Yes<input type='radio' name='Choice' value='Y' >
    &nbsp;&nbsp;No<input type='radio' name='Choice' value='N'>
    &nbsp;&nbsp;Undecided<input type='radio' name='Choice' value="?" >
    &nbsp;&nbsp;<input type=submit value="Vote" >
    <input type='hidden' name='Operation' value='Apply'>
    <input type='hidden' name='TopicId' value='193'>
  </form>
</div>

<div style='height:10.0em;'></div>

 
 
</div>

  

 





<div align='center' class='legalese'>  
&copy; 2011 Hirondelle Systems |
<a href='../source/SourceAction-2.html'><b>Source Code</b></a><IMG class='no-margin' SRC="../images/goldstar.gif" ALT=""> |
<a href="mailto:webmaster@javapractices.com">Contact</a> |
<a href="http://creativecommons.org/licenses/by-nc-sa/1.0/">License</a> |
<a href='../apps/cjp.rss'>RSS</a>
<!-- ukey="2AC36CD2" -->
<!-- ckey="16DF3D87" -->
<br>

 Individual code snippets can be used under this <a href='../LICENSE.txt'>BSD license</a> - Last updated on June 6, 2010.<br>
 Over 150,000 unique IPs last month - <span title='Java Practices 2.6.5, Mon May 16 00:00:00 EDT 2011'>Built with</span> <a href='http://www.web4j.com/'>WEB4J</a>.<br>
 - In Memoriam : Bill Dirani -
</div>

<script src="../../www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2633428-1";
urchinTracker();
</script>



</body>

<!-- Mirrored from www.javapractices.com/topic/TopicAction.do;jsessionid=4FCCB481C702D708A7360133D128E359?Id=193 by HTTrack Website Copier/3.x [XR&CO'2010], Sun, 12 Jun 2011 17:27:06 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=UTF-8"><!-- /Added by HTTrack -->
</html>
